import java.util.Arrays;
import java.util.Scanner;

public class Java6 {

    public static void main(String[] args) {
        //for循环遍历数组
        int [] array = {71,25,13,84,95,66};
        System.out.println(array);

        //通过下标访问的
        for (int i = 0; i < array.length; i++) {
            System.out.println(array[i]);
        }
        System.out.println("===============");
        //和下标没有关系
        //for-each
        for (int x : array) {
            System.out.println(x);
        }
        System.out.println("===============");
        //对数组排序
        Arrays.sort(array);
        //俩种方法
        //以字符串形式输出 单纯打印数组
        String ret = Arrays.toString(array);
        System.out.println(Arrays.toString(array));
        System.out.println(ret);
    }

    public static void main20(String[] args) {
        int [] array = {1,2,3,4,5,6};
        array[0] = 99;
        System.out.println(array[0]);
        System.out.println(array[1]);
        //求数组长度        数组名.length就可以自动求出长度
        System.out.println(array.length);
    }

    public static void main19(String[] args) {
        boolean [] array = new boolean[10];//false
        char [] array2 = new char[10]; //'\u0000'
        System.out.println("====");

        String str = new String("hello");
        String str2 = "hello";
    }

    public static void main18(String[] args) {
        //定义方式
        int [] array = {1,2,3,4,5,6};//常用
        int [] array2 = new int[]{1,2,3,4,5,6};
        int [] array3 = new int[10];//只是分配了内存

        //int array4[] = {1,2,3,4};//不规范

        int[] array5;
        array5 = new int[]{1,2,3,4};
    }

    //---------------------------------------------------

    public static void hnt(int n,char pos1,char pos2,char pos3) {
        if (n == 1) {
            move(pos1,pos3);
            return;
        }
        hnt(n-1,pos1,pos3,pos2);
        move(pos1,pos3);
        hnt(n-1,pos2,pos1,pos3);
    }

    public static void move(char pos1,char pos2) {
        System.out.print(pos1 +"->"+ pos2);
    }

    public static void main17(String[] args) {
        //河内塔
        hnt(1,'A','B','C');
        System.out.println();
        hnt(2,'A','B','C');
        System.out.println();
        hnt(3,'A','B','C');
    }

    public static void main16(String[] args) {
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入月份：");
        int n = scanner.nextInt();
        int days = 0;
        switch (n) {
            case 2:days = 28;
            break;
            case 4:
            case 6:
            case 9:
            case 11:days = 30;
            break;
            default:days = 31;
        }
        System.out.println(n+"月份为"+days+"天");
    }

    public static void main15(String[] args) {
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入一个整数：");
        int n = scanner.nextInt();
        int sum = 0;
        while (n != 0) {
            int i = n % 10;
            n = n / 10;
            sum += i;
        }
        System.out.println(sum);
    }

    public static int fib2(int m) {
        if (m == 1 || m == 2) {
            return 1;
        }
        return (fib(m-1) + fib(m - 2));
    }

    public static void main14(String[] args) {
        System.out.println(fib2(5));
    }

    public static int sum(int n) {
        if (n < 10) {
            return 1;
        }
        return (n % 10 + sum(n / 10));
    }

    public static void main13(String[] args) {
        System.out.println(sum(1729));
    }

    public static int add(int n) {
        if (n == 1) {
            return 1;
        }
        return n + add(n-1);
    }

    public static void main12(String[] args) {
        //递归求 1 + 2 + 3 + ... + 10
        System.out.println(add(10));
    }

    public static void fam(int n) {
        if (n <= 9) {
            System.out.println(n);
            return;
        }
        fam(n / 10);
        System.out.println(n % 10);
    }

    public static void main11(String[] args) {
        //递归按顺序打印一个数字的每一位(例如 1234 打印出 1 2 3 4)
        fam(1234);
    }

    public static int fac(int c) {
        if (c == 1) {
            return 1;
        }
        int tmp = c * fac(c-1);
        return tmp;
    }

    public static void main10(String[] args) {
        System.out.println(fac(5));
    }

    public static int fib(int n) {
        //斐波那契数列
        if (n == 1 || n == 2) {
            return 1;
        }
        int f1 = 1;
        int f2 = 1;
        int f3 = 0;
        for (int i = 3; i <= n; i++) {
            f3 = f1 + f2;
            f1 = f2;
            f2 = f3;
        }
        return f3;
    }

    public static void main9(String[] args) {
        System.out.println(fib(1));
        System.out.println(fib(2));
        System.out.println(fib(3));
        System.out.println(fib(4));
        System.out.println(fib(5));
    }

    public static void login() {
        int count = 3;
        Scanner scanner = new Scanner(System.in);
        while (count != 0) {
            System.out.println("请输入你的密码");
            String passWord = scanner.nextLine();
            //if (passWord == "123456") {
            if (passWord.equals("123456")) {
                System.out.println("登录成功");
                break;
            }else {
                count--;
                System.out.println("密码错误");
            }
        }
    }

    public static void func2(int n) {
        while (n != 0) {
            System.out.println(n % 10);
            n = n / 10;
        }
    }

    public static double func1() {
        double sum = 0;
        int flg = 1;
        for (int i = 1; i <= 100; i++) {
            sum = sum + 1.0/i * flg;
            flg = -flg;
        }
        return sum;
    }


    public static void main8(String[] args) {
        func2(123);
        /*double n = func1();
        System.out.println(n);*/
    }

    public static void main7(String[] args) {
        Scanner scanner = new Scanner(System.in);
        long mima = 123;
        int cishu = 3;
        int i = 0;
        for ( i = 0; i <= cishu; i++) {
            int mi = scanner.nextInt();
            if (mi == mima) {
                System.out.println("密码正确");
                break;
            }else {
                System.out.println("密码错误，重新输入");
            }
        }
        if (i >= 3) {
            System.out.println("退出程序");
        }
    }

    public static int maxNum(int a,int b) {
        if (a > b) {
            return a;
        }else {
            return b;
        }
    }

    public static double maxNum(double a,double b,double c) {
        double n = 0;
        if (a > b) {
            n = a;
        }else {
            n = b;
        }
        if (c > n) {
            n = c;
        }
        return n;
    }

    public static void main6(String[] args) {
        int m = maxNum(11,22);
        System.out.println(m);
        double num = maxNum(1.1,2.2,3.3);
        System.out.println(num);
    }

    public static int sumNum(int a,int b) {
        return a+b;
    }

    public static double sumNum(double d1,double d2) {
        return d1+d2;
    }

    public static void main5(String[] args) {
        int s = sumNum(1,2);
        System.out.println(s);
        double n = sumNum(1.3,2.2);
        System.out.println(n);
    }

    public static int max(int a,int b,int c) {
        int m = max(a,b);
        return max(m,c);
    }

    public static int max(int a,int b) {
        return a > b ? a : b;
    }

    public static void main4(String[] args) {
        System.out.println(max(1, 2, 3));
    }

    public static void main3(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        for (int i = 1; i <= n; i++) {
            for (int j = 1; j <= i; j++) {
                System.out.print(i+"*"+j+"=="+i*j+"  ");
            }
            System.out.println();
        }
    }

    public static void main2(String[] args) {
        //输出一个整数的每一位，如：123的每一位是3，2，1
        int a = 123;
        int sum = 0;
        while (a != 0) {
            sum = a % 10;
            a = a / 10;
            System.out.println(sum);
        }
    }

    public static void main1(String[] args) {
        //计算1/1-1/2+1/3-1/4+1/5 …… + 1/99 - 1/100 的值
        double sum = 0;
        int ret = 1;
        for (int i = 1; i <= 100; i++) {
            sum += (ret)*1.0/i;
            ret = -(ret);
        }
        System.out.println(sum);
    }
}
